#include "SmsServiceIPC.h"

CSmsServiceIPC::CSmsServiceIPC( const TUid aUid, const TUint32 aKey,
        MSmsServiceIPCObserver &aNotifier) :
    CActive(EPriorityStandard), iUid(aUid), iKey(aKey), iObserver(aNotifier)
{
}
CSmsServiceIPC* CSmsServiceIPC::NewLC( const TUid aUid, const TUint32 aKey,
        MSmsServiceIPCObserver &aNotifier)
{

    CSmsServiceIPC *self = new (ELeave) CSmsServiceIPC(aUid, aKey, aNotifier);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}
CSmsServiceIPC* CSmsServiceIPC::NewL( const TUid aUid, const TUint32 aKey,
        MSmsServiceIPCObserver &aNotifier)
{
    CSmsServiceIPC *self = CSmsServiceIPC::NewLC(aUid, aKey, aNotifier);
    CleanupStack::Pop(self);
    return self;
}

void CSmsServiceIPC::ConstructL()
{

    CActiveScheduler::Add(this);
    TInt ret= iProperty.Define(iUid,iKey,RProperty::EInt);
    if (ret != KErrNone &&
              ret != KErrAlreadyExists)
          {
              User::Leave(ret);
          }
    User::LeaveIfError(iProperty.Attach(iUid, iKey,EOwnerThread));
    iProperty.Subscribe(iStatus);
    SetActive();
    //RunL();
}
void CSmsServiceIPC::RunL()
{
    TInt value = 0;
    iProperty.Get(value);
    iObserver.IntPropertyUpdatedL(value);
    iProperty.Subscribe(iStatus);
       SetActive();
}

CSmsServiceIPC::~CSmsServiceIPC()
{
    this->Cancel();
}

void CSmsServiceIPC::DoCancel()
{
    iProperty.Cancel();
}
